package com.zide.member.controller.community;

import com.zide.common.core.domain.CommonResult;
import com.zide.common.core.domain.PageResult;
import com.zide.member.service.community.CommunityEssayService;
import com.zide.member.vo.result.community.CommEssayResultVO;
import com.zide.member.vo.save.community.CommEssaySaveVO;
import com.zide.member.vo.search.community.CommEssaySearchVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import static com.zide.common.core.domain.CommonResult.getResult;
import static com.zide.common.core.domain.CommonResult.success;

/**
 * @author 石添
 * @date 2024/8/24
 */
@Slf4j
@RestController
@RequestMapping("/community/essay")
@Tag(name = "会员管理")
@RequiredArgsConstructor
public class CommunityEssayController {

    private final CommunityEssayService communityEssayService;

    @Operation(summary = "社区文章列表")
    @GetMapping("page")
    public CommonResult pageList(CommEssaySearchVO searchVO) {
        PageResult<CommEssayResultVO> result = communityEssayService.pageList(searchVO);
        return success(result);
    }

    @Operation(tags = "发布社区文章")
    @PostMapping
    public CommonResult pushEssay(@RequestBody CommEssaySaveVO saveVO) {
        return getResult(communityEssayService.pushEssay(saveVO));
    }

    @Operation(tags = "修改社区文章")
    @PutMapping
    public CommonResult modifyEssay(@RequestBody CommEssaySaveVO saveVO) {
        return getResult(communityEssayService.modifyEssay(saveVO));
    }

    @Operation(tags = "删除社区文章")
    @DeleteMapping
    public CommonResult removeEssay(@RequestBody Long[] ids) {
        return getResult(communityEssayService.removeEssay(ids));
    }

    @Operation(summary = "社区文章列表")
    @GetMapping("detail/{id}")
    public CommonResult searchDetail(@PathVariable("id") Long id) {
        return success(communityEssayService.searchDetail(id));
    }

}
